
const util = require("../../utils/config.js");
//index.js
//获取应用实例
const app = getApp()
const http_host = util.http_host;
const agent_id = util.agent_id;
const img_url = util.img_url;
const appId = util.appId;
const secret = util.secret;
var QQMapWX = require('../../qqmap-wx-jssdk.min.js');
var qqmapsdk;
Page({
  data: {
    id: '先生',
    city: '点击选择',
    name: '',
    phone: '',
    cityDetail: '',
    address: '',   //当前定位的城市
    nothing: false,
    //当前需要编辑的地址
    editAddress: '',
  },
  getAddress: function () {
    var that = this;
    wx.chooseLocation({
      success: function (res) {
        // if (res.address.length > 10) {
        //   res.address = res.address.substr(0, 10) + '...'
        // }
        that.setData({
          city: res.address
        })
      },
    })
  },
  chooseId: function(e) {
    var type = e.currentTarget.dataset.id;
    this.setData({
      id: type
    })
  },
  toEditAddress: function() {
    this.setData({
      pageType: 2
    })
  },
  noChoose: function() {
    this.setData({
      pageType: 1,
      city: '点击选择',
    })
  },
  setName: function (e) {
    this.setData({
      name: e.detail.value
    })
  },
  setPhone: function (e) {
    this.setData({
      phone: e.detail.value
    })
  },
  setCityDetail: function(e) {
    this.setData({
      cityDetail: e.detail.value
    })
  },
  // saveAddress: function() {
  //   console.log(this.data)
  //   wx.navigateBack({
  //     url: '../address/address',
  //   })
  //   wx.request({
  //     url: '',
  //     data: this.data,
  //     success: function(res) {
  //       console.log(res)
  //     }
  //   })
  // },
  /**
   * 用户点击右上角分享
   */onLoad: function (e){
     var that = this;
      var id = e.id;  //当前用户
      if(id){
        wx.request({
          url: http_host + 'EditMemberAddress',
          data: {
            id: id
          },
          header: {
            'Content-Type': 'application/json'
          },
          success: function (res) {
            that.setData({
              editAddress:res.data
            })
          }
        })

      }
   },
  onShareAppMessage: function () {
    return {
      title: '微信小程序',
      desc: '6666666666666666666666666666',
      path: '/pages/user?id=123'
    }
  },
  formSubmit: function (e) {

    console.log(1)
    console.log(e)
    console.log('form发生了submit事件，携带数据为：', e.detail.value)
    var openId = app.globalData.openId;
    const datas = [];
       var name = e.detail.value.name;
       var cityDetail = e.detail.value.cityDetail;
      var city = e.detail.value.city;
      var phone = e.detail.value.phone;
      var openId = openId;
      var sex = e.detail.value.sex;
      var id = e.detail.value.id;
    //提交数据到数据库
    wx.request({
      url: http_host + 'putaddress',
      data: {
        name: name,
        city : city,
        phone: phone,
        cityDetail: cityDetail,
        openId: openId,
        sex: sex,
        id: id
      },
      header: {
        'Content-Type': 'application/json'
      },
      success: function (res) {
        wx.navigateTo({
          url: '../useroperation/useroperation?operation=address&openId=' + openId,
        })
      }
    })
  },
  formReset: function () {
    console.log('form发生了reset事件')
  }
})